/* 
    操作大文件（流式操作）
    fs.createReadStream(path[,options])
    fs.createWriteStream(path[,options])
*/
const fs = require("fs");
const path = require('path');

let strPath = path.join(__dirname, '../02code', 'abc.txt');
let dPath = path.join("C:Users\\hoing\\Desktop", 'abc.txt');

let readStream = fs.createReadStream(strPath);
let writeStream = fs.createWriteStream(dPath);

// 基本事件的除了方式
// let num = 0;
// readStream.on('data',(chunk)=>{
//     num++;
//     writeStream.write(chunk);
// });

// readStream.on('end',()=>{
//     console.log(num);
// });

// pipe的作用直接把输入流和输出流
// readStream.pipe(writeStream);

fs.createReadStream(strPath).pipe(fs.createWriteStream(dPath));